package com.asset.salesforce.view;

import java.awt.Color;
import java.util.List;


import com.asset.salesforce.domain.InvoiceSku;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;

public class InvoiceProductTable {
	
	public static Font normalFont = new Font(FontFactory.getFont(String.valueOf(Font.TIMES_ROMAN),BaseFont.TIMES_ROMAN,9,Font.NORMAL));
	
	public PdfPTable pdfPTable(List<InvoiceSku> invoiceSkus)throws Exception{
				
			PdfPTable table = new PdfPTable(8);
		      PdfPCell cell = new PdfPCell (new Paragraph ("SKU Invoice",new Font(FontFactory.getFont(String.valueOf(Font.TIMES_ROMAN),BaseFont.TIMES_ROMAN,11,Font.BOLD))));
		      cell.setColspan (8);
		      cell.setHorizontalAlignment (Element.ALIGN_CENTER);
		      cell.setBackgroundColor (new Color (128, 200, 128));
		      //cell.setPadding (9.0f);
		      cell.setFixedHeight(18);
		      //cell.setBorderWidth(20);
		      table.addCell (cell);
		      
		      cell = new PdfPCell(new Paragraph("Name",normalFont));
		      cell.setHorizontalAlignment (Element.ALIGN_CENTER);
		      cell.setBackgroundColor (new Color (255, 200, 0));
		      //cell.setPadding (9.0f);
		      cell.setFixedHeight(18);
		      table.addCell (cell);
		      
		      cell = new PdfPCell(new Paragraph("Code",normalFont));
		      cell.setHorizontalAlignment (Element.ALIGN_CENTER);
		      cell.setBackgroundColor (new Color (255, 200, 0));
		      //cell.setPadding (9.0f);
		      cell.setFixedHeight(18);
		      table.addCell (cell);
		      
		      cell = new PdfPCell(new Paragraph("Discount",normalFont));
		      cell.setHorizontalAlignment (Element.ALIGN_CENTER);
		      cell.setBackgroundColor (new Color (255, 200, 0));
		      //cell.setPadding (9.0f);
		      cell.setFixedHeight(18);
		      table.addCell (cell);
		      
		      cell = new PdfPCell(new Paragraph("Price",normalFont));
		      cell.setHorizontalAlignment (Element.ALIGN_CENTER);
		      cell.setBackgroundColor (new Color (255, 200, 0));
		      //cell.setPadding (9.0f);
		      cell.setFixedHeight(18);
		      table.addCell (cell);
		      
		      cell = new PdfPCell(new Paragraph("Quantity",normalFont));
		      cell.setHorizontalAlignment (Element.ALIGN_CENTER);
		      cell.setBackgroundColor (new Color (255, 200, 0));
		      //cell.setPadding (9.0f);
		      cell.setFixedHeight(18);
		      table.addCell (cell);
		      
		      cell = new PdfPCell(new Paragraph("Tax1",normalFont));
		      cell.setHorizontalAlignment (Element.ALIGN_CENTER);
		      cell.setBackgroundColor (new Color (255, 200, 0));
		      //cell.setPadding (9.0f);
		      cell.setFixedHeight(18);
		      table.addCell (cell);
		      
		      cell = new PdfPCell(new Paragraph("Tax2",normalFont));
		      cell.setHorizontalAlignment (Element.ALIGN_CENTER);
		      cell.setBackgroundColor (new Color (255, 200, 0));
		      //cell.setPadding (9.0f);
		      cell.setFixedHeight(18);
		      table.addCell (cell);
		      
		      cell = new PdfPCell(new Paragraph("Line Total",normalFont));
		      cell.setHorizontalAlignment (Element.ALIGN_CENTER);
		      cell.setBackgroundColor (new Color (255, 200, 0));
		      //cell.setPadding (10.0f);
		      cell.setFixedHeight(18);
		      table.addCell (cell);
		      table.setWidthPercentage(100);
		      //table.setLockedWidth(true);
		     // table.setComplete(true);

			    	  if(invoiceSkus.size()>0){
							for (InvoiceSku invoiceSku : invoiceSkus) {
								if(invoiceSku.getStockSku()!=null){
									table.addCell(new Paragraph(invoiceSku.getStockSku().getName(),normalFont));

								}
								else
								{
									table.addCell(new Paragraph("",normalFont));
								}
								if(invoiceSku.getStockSku()!=null){
									table.addCell(new Paragraph(invoiceSku.getStockSku().getCode(),normalFont));

								}
								else
								{
									table.addCell(new Paragraph("",normalFont));
								}
								if(invoiceSku.getDiscount()!=null){
									table.addCell(new Paragraph(invoiceSku.getDiscount(),normalFont));

								}
								else
								{
									table.addCell(new Paragraph("",normalFont));
								}
								if(invoiceSku.getPrice()!=null){
									table.addCell(new Paragraph(invoiceSku.getPrice(),normalFont));

								}
								else
								{
									table.addCell(new Paragraph("",normalFont));
								}
								if(invoiceSku.getQuantity()!=null){
									table.addCell(new Paragraph(invoiceSku.getQuantity(),normalFont));
								}
								else
								{
									table.addCell(new Paragraph("",normalFont));
								}
								if(invoiceSku.getTaxOne()!=null){
									table.addCell(new Paragraph(invoiceSku.getTaxOne().toString(),normalFont));
								}
								else{
									table.addCell(new Paragraph("",normalFont));
								}
								if(invoiceSku.getTaxTwo()!=null){
									table.addCell(new Paragraph(invoiceSku.getTaxTwo().toString(),normalFont));

								}
								else{
									table.addCell(new Paragraph("",normalFont));
								}
								if(invoiceSku.getTotalPrice()!=null){
									table.addCell(new Paragraph(invoiceSku.getTotalPrice(),normalFont));
								}
								else
								{
									table.addCell(new Paragraph("",normalFont));
								}
						}
						}
			   //   }
			   //   table.setCellsFitPage(true);
			    	  table.setSpacingBefore(20f);
			    	  table.setSpacingAfter(10f);
					return table;
		}
	}

